package com.yanhao.aop.login;

import android.util.Log;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.reflect.MethodSignature;

/**
 * 登录拦截
 */
@Aspect
public class LoginNeedAspectj {

    private static final String TAG = "Login_TAG";

    @Around("execution(@com.yanhao.aop.login.LoginNeed * *(..))")
    public void loginCheck(ProceedingJoinPoint joinPoint) throws Throwable {
        Log.e(TAG, "切面检查: --- 进入 ---");

        MethodSignature signature = (MethodSignature) joinPoint.getSignature();

        LoginNeed annotation = signature.getMethod().getAnnotation(LoginNeed.class);

        String account = annotation.account();
        String password = annotation.password();
        if (account.equals("yanhao") && password.equals("123456")) {
            joinPoint.proceed();
        } else {
            Log.e(TAG, "切面检查: --- 拦截 ---");
        }
        Log.e(TAG, "切面检查: --- 结束 ---");
    }
}
